files=$1
cd $1
dump_memory_file="total_mem.txt"
if test -f $dump_memeory_file; then rm $dump_memory_file; fi
printf "%-48s%-96s%-48s%-48s%-48s%-48s\n" "timeMs" "smaps_file" "TotalRss" "TotalPss">$dump_memory_file
# printf "%-48s%-96s%-48s%-48s%-48s%-48s%-48s%-48s%-48s\n" "timeMs" "smaps_file" "TotalRss" "TotalPss" "knPss" "arktsPss" "nativePss">$dump_memory_file
for file in ./*
do
  echo $file
  if [[ "$file" != "./total_mem.txt" ]]
  then
    timeMs=`echo $file | awk -F '[//_ .]' '{print $10}'`
    RSS=`cat ${file} | grep Rss | awk '{sum+=$2} END {print sum}'`
    PSS=`cat ${file} | grep Pss | awk '{sum+=$2} END {print sum}'`
    knPss=`cat ${file} | grep -A 10 "kotlin_native_hby" | grep "Pss" | awk '{sum+=$2} END {print sum}'`
    arkTSPss=`cat ${file} | grep -A 10 "anon:ArkTS" | grep "Pss" | awk '{sum+=$2} END {print sum}'`
    nativePss=`cat ${file} | grep -A 10 "native_heap" | grep "Pss" | awk '{sum+=$2} END {print sum}'`
    printf "%-48s%-96s%-48s%-48s%-48s%-48s\n" "$timeMs" "$file" "$RSS" "$PSS">>$dump_memory_file
    # printf "%-48s%-96s%-48s%-48s%-48s%-48s%-48s%-48s%-48s\n" "$timeMs" "$file" "$RSS" "$PSS" "$knPss" "$arkTSPss" "$nativePss">>$dump_memory_file
  fi
done